package com.example.dictionary.config;

import com.example.memento.model.DictionarySource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 词典配置属性
 */
@Component
@ConfigurationProperties(prefix = "dictionaries")
public class DictionaryProperties {
    
    private List<DictionarySource> sources;
    private DownloadConfig download = new DownloadConfig();
    private StorageConfig storage = new StorageConfig();
    private ParsingConfig parsing = new ParsingConfig();
    
    // Getters and Setters
    public List<DictionarySource> getSources() { return sources; }
    public void setSources(List<DictionarySource> sources) { this.sources = sources; }
    
    public DownloadConfig getDownload() { return download; }
    public void setDownload(DownloadConfig download) { this.download = download; }
    
    public StorageConfig getStorage() { return storage; }
    public void setStorage(StorageConfig storage) { this.storage = storage; }
    
    public ParsingConfig getParsing() { return parsing; }
    public void setParsing(ParsingConfig parsing) { this.parsing = parsing; }
    
    public static class DownloadConfig {
        private int maxConcurrent = 3;
        private int timeoutSeconds = 300;
        private int retryAttempts = 3;
        private int chunkSize = 8192;
        /**
         * 全局下载保存路径（支持多个路径，用逗号分隔）
         * 下载时会检查每个路径的磁盘空间，随机选择有足够空间的路径
         * 示例: "data/res,/mnt/disk1/res,/mnt/disk2/res"
         */
        private String savePath;
        
        // Getters and Setters
        public int getMaxConcurrent() { return maxConcurrent; }
        public void setMaxConcurrent(int maxConcurrent) { this.maxConcurrent = maxConcurrent; }
        
        public int getTimeoutSeconds() { return timeoutSeconds; }
        public void setTimeoutSeconds(int timeoutSeconds) { this.timeoutSeconds = timeoutSeconds; }
        
        public int getRetryAttempts() { return retryAttempts; }
        public void setRetryAttempts(int retryAttempts) { this.retryAttempts = retryAttempts; }
        
        public int getChunkSize() { return chunkSize; }
        public void setChunkSize(int chunkSize) { this.chunkSize = chunkSize; }
        
        public String getSavePath() { return savePath; }
        public void setSavePath(String savePath) { this.savePath = savePath; }
    }
    
    public static class StorageConfig {
        private String type = "rocksdb";
        private String path = "./data/dictionaries";
        private String rocksdbPath = "./data/rocksdb";
        
        // Getters and Setters
        public String getType() { return type; }
        public void setType(String type) { this.type = type; }
        
        public String getPath() { return path; }
        public void setPath(String path) { this.path = path; }
        
        public String getRocksdbPath() { return rocksdbPath; }
        public void setRocksdbPath(String rocksdbPath) { this.rocksdbPath = rocksdbPath; }
    }
    
    public static class ParsingConfig {
        private int batchSize = 1000;
        private int threadPoolSize = 4;
        private String encoding = "UTF-8";
        
        // Getters and Setters
        public int getBatchSize() { return batchSize; }
        public void setBatchSize(int batchSize) { this.batchSize = batchSize; }
        
        public int getThreadPoolSize() { return threadPoolSize; }
        public void setThreadPoolSize(int threadPoolSize) { this.threadPoolSize = threadPoolSize; }
        
        public String getEncoding() { return encoding; }
        public void setEncoding(String encoding) { this.encoding = encoding; }
    }
}
